/*
 * @Author: szx
 * @Date: 2022-05-02 13:46:03
 * @LastEditTime: 2022-05-02 13:52:37
 * @Description:
 * @FilePath: \leetcode\100-199\173\173_2.js
 */
/*
 * @Author: szx
 * @Date: 2022-05-02 13:39:30
 * @LastEditTime: 2022-05-02 13:41:02
 * @Description:
 * @FilePath: \leetcode\100-199\173\173.js
 */
var BSTIterator = function (root) {
    this.cur = root;
    this.stack = [];
};

BSTIterator.prototype.next = function () {
    while (this.cur) {
        this.stack.push(this.cur);
        this.cur = this.cur.left;
    }
    this.cur = this.stack.pop();
    const res = this.cur.val;
    this.cur = this.cur.right;
    return res;
};

BSTIterator.prototype.hasNext = function () {
    return this.cur != null || this.stack.length;
};
